﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace ZaidimasSandelys.Models.DataStructures
{
    /// <summary>
    /// WPF Point klasė turi tik integer koordinates ir double koordinatės. Ši klasė turi integer koordinates ir 
    /// papildomas operacijas (lygybės ir sudėties)
    /// <code>Point</code> su perprogramuoto lygybės ir sudėties operacijomis
    /// </summary>
    public class Movement
    {
        public int Width { get; set; }
        public int Height { get; set; }

        public Movement(int width, int height)
        {
            this.Width = width;
            this.Height = height;
        }
        public Movement(Movement another) : this(another.Width, another.Height)
        {
        }

        public static bool operator ==(Movement m1, Movement m2)
        {
            // Objektai lygūs kai m1 ir m2 yra nuorodos į tą patį objektą
            if (System.Object.ReferenceEquals(m1, m2))
                return true;

            // Čia patenkam kai bent vienas elementas yra ne NULLas.
            // (object)m1 == null duoda tą patį kaip ((object)m1 == null) && ((object)m2 != null)
            if ((object)m1 == null || (object)m2 == null)
                return false;

            return m1.Width == m2.Width && m1.Height == m2.Height;
        }

        public static bool operator !=(Movement m1, Movement m2)
        {
            return !(m1 == m2);
        }

        public override bool Equals(object obj)
        {
            if (obj == null || !typeof(Movement).IsAssignableFrom(obj.GetType()))
                return false;
            var m1 = (Movement)obj;
            return m1.Width == this.Width && m1.Height == this.Height;
        }
        public override int GetHashCode()
        {
            return (this.Width + this.Height).GetHashCode();
        }
        
        public long DictionaryKey
        {
            get 
            {
                long tmp = this.Width;
                tmp <<= 16;
                tmp += (long)this.Height;
                return tmp; 
            }
        }

        public static Movement operator +(Movement m1, Movement m2)
        {
            if ((object)m1 == null || (object)m2 == null)
                return null;
            return new Movement(m1.Width + m2.Width, m1.Height + m2.Height);
        }

        public Point GetDrawingPoint(Size multiplicator)
        {
            return new Point(this.Width * multiplicator.Width, this.Height * multiplicator.Height);
        }
    }
}
